package dem1;

import java.util.Arrays;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-04-03
 * Time: 10:03
 */
public class Test {
    private static void revolve(int[] nums){
        int tmp = nums[nums.length - 1];
        for(int i = nums.length - 1; i >= 1 ; i--){
            nums[i] = nums[i - 1];
        }
        nums[0] = tmp;
    }
    public static void rotate1(int[] nums, int k) {
        while(k > 0){
            revolve(nums);
            k--;
        }
    }

    public static void rotate(int[] nums, int k) {
        k = k % nums.length;
        if(k == 0){
            return;
        }
        int k2 = k;
        int[] arr = new int[k];
        int j = 1;
        while(k > 0){
            arr[k - 1] = nums[nums.length - j];
            j++;
            k--;
        }
        int x = 1;
        for (int i = nums.length - 1 - k2; i >= 0; i--){
            nums[nums.length - x] = nums[i];
            x++;
        }
        for(int i = 0;i < arr.length;i++){
            nums[i] = arr[i];
        }
        arr = null;
    }

    public static int removeElement(int[] nums, int val) {
        int tmp = 0;
        for(int i = nums.length - 2;i >= 0; i--){
            if(nums[i] == val){
                tmp = nums[i];
                nums[i] = nums[i+1];
                nums[i+1] = tmp;
                i++;
            }
        }
        return nums.length - val;
    }

    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        int i = m - 1;
        int j = n - 1;
        int k = 1;
        while(i >= 0 && j >= 0){
            if(nums1[i] > nums2[j]){
                nums1[m + n - k] = nums1[i];
                i--;
            }else{
                nums1[m + n - k] = nums2[j];
                j--;
            }
            k++;
        }
        if(j != 0){
            for(int x = 0;x <= j;i++){
                nums1[x] = nums2[x];
            }
        }
    }

    public static void main(String[] args) {
//        int[] arr2 = {1,2,2,3};
//        int[] arr1 = new int[8];
//        arr1[0] = 1;
//        arr1[1] = 1;
//        arr1[2] = 4;
//        arr1[3] = 5;
        //removeElement(arr,3);
        //merge(arr1,4,arr2,4);
        //System.out.println(Arrays.toString(arr));

        MyArrayList list  = new MyArrayList();
        for (int i = 0;i < 15; i++){
            list.add(i);
        }
        list.display();//1
        list.remove(12);
        System.out.println(list.contains(4));//2
        list.set(3,10);
        list.add(14,6);
        System.out.println(list.indexOf(20));//3
        list.display();//4
        list.clear();
        list.display();
    }
}
